// 封装

// 数据的封装
var myObject = (function() {
    var _name = 'sven';
    return {
        getName: function() {
            return _name;
        }
    }
})();

console.log(myObject.getName());
console.log(myObject._name);

var Plane = function() {
    this.blood = 100;
    this.attackLevel = 1;
    this.defenseLevel = 1;
};

var plane = new Plane();
plane.blood = 500;
plane.attackLevel = 10;
plane.defenseLevel = 7;
var createFn = function(obj) {
    var F = function() {};
    F.prototype = obj;
    return new F();
}
Object.create = Object.create || function(obj) {
    var F = function() {};
    F.prototype = obj;
    return new F();
}
var clonePlane = Object.create(plane);
plane.defenseLevel = 9;
console.log(clonePlane.defenseLevel)

function Person(name) {
    this.name = name;
}

Person.prototype.getName = function() {
    return this.name;
}

var objectFactory = function() {
    var obj = new Object();
    var Constructor = [].shift.call(arguments);
    obj.__proto__ = Constructor.prototype;
    var ret = Constructor.apply(obj, arguments);
    return typeof ret === 'object' ? ret : obj;
}

var person = objectFactory(Person, 'fywang');
console.log(person);